// pages/mine/feedbak/add/add.js
Page({


  data: {  fileList:[],name:'',list:[],res:'',phone:'',introduce:'',address:'',phoneflag:false,list:[],fileList:[]

  },

  
  onLoad: function (options) {

  },

  
  afterRead(event) {
    const { file } = event.detail;
    console.log(file);
    const that=this
      
    
    
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      
      url: 'https://zujieba.com/index/upload/upload', // 仅为示例，非真实的接口地址
      filePath: file.path,
      name:'file',
      
      success(res) {
        
        const res1=JSON.parse(res.data).name
        const array=that.data.list
        array.push(res1)
     if(!that.data.res){
       var res=  that.data.res+res1}else{
        var res=  that.data.res+","+res1
       }
      
        that.setData({
          list:array,
         res
        })
        
        
        
        
        console.log(that.data.res);
        const url1="https://zujieba.com/file_index/"+res1
        
        console.log(url1);
        
        const { fileList = [] } = that.data;
        const object={}
        object.url=url1
        object.name=2
        object.deletable=true
        
       fileList.push(object) 
        that.setData({ fileList });
      }
      
    });
  },
  deleteclick2(e){
    const index=  e.detail.index
    const list=this.data.fileList
        list.splice(index,1)
       this.setData({
         fileList:list
       })
           
         
    },
    change2(e){
      this.setData({
        name:e.detail.value
      })
    },
    change3(e){
       this.setData({
         phone:e.detail.value
       })
    let phoneflag=this.checkMobile(e.detail.value)
    this.setData({
      phoneflag
    })
    },
    change4(e){
      this.setData({
        address:e.detail.value   
      })
    },
    change8(e){
       this.checkMobile1(e.detail.value)

    },
  
    change5(e){
      this.setData({
        introduce:e.detail.value
      })
    },
  
      submit(){
      
        if(this.data.name.trim()==''||this.data.phone.trim()==''||this.data.address.trim()==''||this.data.introduce.trim()==''||this.data.list.length==0){
          return wx.showToast({
            title: '请填写完整',
            icon:'none'
          })
        }
        console.log(this.data.list);
        console.log(this.data.fileList);
        
        const name=this.data.name
        const phone=this.data.phone
        const address=this.data.address
        const content=this.data.introduce
        const uid=wx.getStorageSync('uid')
        var pic=this.data.list
           const params={name,phone,address,content,uid,pic}  
          wx.request({
            url: 'https://zujieba.com/api/repair/repair.html',
            data:params,
            method:'POST',
            success:(res)=>{
              console.log(res);
              if(res.data.success==1){
                wx.navigateBack({
                  complete: (res) => {},
                })
                wx.showToast({
                  title: res.data.tips,
                })
              }

              
            }
          })
          
        
      },
      checkMobile(e){
    
        if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(e))){
           
            
            return false;
        }
        else{
          return true
        }
    },
    checkMobile1(e){
    
      if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(e))){
          wx.showToast({
            title: '请输入正确的手机号',
            icon:'none'
          })
          
          return false;
      }
      else{
        return true
      }
  }

 
})